<template>
	<view>
		<view class="uni-form-item uni-column">
			<view class="title"><text class="uni-form-item__title">账号</text></view>
			<view class="uni-input-wrapper">
				<input class="uni-input" maxlength="10" placeholder="请输入账号" v-model="account" />
			</view>
		</view>
		<view class="uni-form-item uni-column">
			<view class="title"><text class="uni-form-item__title">密码</text></view>
			<view class="uni-input-wrapper">
				<input class="uni-input" maxlength="10" placeholder="请输入密码" password="true" v-model="password" />
			</view>
		</view>
		<view class="uni-padding-wrap uni-common-mt">
			<view class="button-sp-area">
				<button type="primary" plain="true" @click="mylogin()">登录</button>
			</view>
		</view>
	</view>
</template>

<script>
	import loginservice from '../../myservice/loginservice.js';
	import commonservice from '../../myservice/commonservice.js'
	import {mapState,mapMutations} from 'vuex'

	export default {
		data() {
			return {
				account: "admin",
				password: "000000"
			}
		},
		computed: {
			...mapState(['hasLogin', 'gotoinfo']),
		},
		methods: {
			//绑定
			...mapMutations(['login', 'logout']), //方法设置登录
			mylogin() {
				var that = this;
				console.log(this.account + "_" + this.password);
				loginservice.LoginJwt({
					'account': that.account,
					'password': that.password
				}).then(res => {
					console.log(JSON.stringify(res));
					var access_token = res.data.access_token;

					if (access_token != null) {
						commonservice.AccessToken = access_token;//这个没用了，为了兼容，先保留
						// uni.switchTab({
						// 	url: '../index/index'
						// })
						that.login(access_token);
						setTimeout(function() {
						
							switch (that.gotoinfo.pagetype) {
								case 'reLaunch':
									uni.reLaunch({
										url: that.gotoinfo.pageurl
									});
									break;
								case 'navigateTo':
									uni.navigateTo({
										url: that.gotoinfo.pageurl
									});
									break;
								case 'redirectTo':
									uni.redirectTo({
										url: that.gotoinfo.pageurl
									});
									break;
								case 'switchTab':
									uni.switchTab({
										url: that.gotoinfo.pageurl
									});
									break;
								default:
									uni.reLaunch({
										url: that.gotoinfo.pageurl
									});
									break;
							}
						
							that.gotoinfo.pageurl = '/pages/index/index';
							that.gotoinfo.pagetype = 'reLaunch';
						}, 500)
					} else {
						uni.showToast({
							icon: 'none',
							title: res.data.Message[0]
						});
					}
				});
			}
		},
	}
</script>

<style>
</style>
